/**
 * @file Driver_Timer.c
 * @brief 
 * @author 2bam 
 * @version 1.0
 * @date 2024-12-07
 * @copyright Copyright (c) 2024  NULL
 * 
 * @change log:
 * Date           Version Author   Describe
 * 2024-12-07     1.0     2bam     first version
 */

/* Includes -------------------------------------------------------------------*/
#include "tim.h"
#include "Driver_Timer.h"
#include "Driver_Serial.h"
#include "../../Component/MultiButton/multi_button.h"

/* define ---------------------------------------------------------------------*/

/* typedef --------------------------------------------------------------------*/

/* variables ------------------------------------------------------------------*/

/* Private function prototypes ------------------------------------------------*/


void TimerStart(TIM_HandleTypeDef *htim)
{
    /* Check the TIM handle allocation */
    if (htim == NULL)
    {
        return;
    }
    __HAL_TIM_CLEAR_FLAG(htim,TIM_FLAG_UPDATE);
    HAL_TIM_Base_Start_IT(htim);
}

/**
 * @brief 
 * @param  htim        My Param doc
 * @param  Channel     My Param doc
 * @date 2024-12-11
 * @author 2bam 
 */
void PWMStart(TIM_HandleTypeDef *htim,uint32_t Channel)
{
    /* Check the TIM handle allocation */
    if (htim == NULL)
    {
        return;
    }

    HAL_TIM_PWM_Start(htim, Channel);
}


void PWMLED(TIM_HandleTypeDef *htim,uint32_t Channel)
{
    for(int i=0;i<100;i++)
    {
        __HAL_TIM_SET_COMPARE(htim,Channel,i);
        HAL_Delay(10);
    }

    for(int i=99;i>=0;i--)
    {
        __HAL_TIM_SET_COMPARE(htim,Channel,i);
        HAL_Delay(10);
    }
    
}

